#include "./src/list.h"

extern funSeqList SeqListfunc;

typedef struct __teacher
{
    int age;
    char name[32];
} teacher;

int main(int argc, const char *argv[])
{
    int i = 0;
    seqList *list = NULL;
    teacher t1, t2, t3, t4, t5;

    t1.age = 31;
    memcpy(t1.name, "George", sizeof("George"));
    t2.age = 32;
    memcpy(t2.name, "Page", sizeof("Page"));
    t3.age = 33;
    memcpy(t3.name, "PeppaPig", sizeof("PeppaPig"));
    t4.age = 34;
    memcpy(t4.name, "zhangsan", sizeof("zhangsan"));
    t5.age = 35;
    memcpy(t5.name, "lisi", sizeof("lisi"));

    list = SeqListfunc.create(8);
    if (list == NULL)
    {
        printf("func create() error, return NULL\n");
        return -1;
    }
    // 插入
    SeqListfunc.insert(list, (ListNode *)&t1, 0); //头插入法
    SeqListfunc.insert(list, (ListNode *)&t2, 0); //头插入法
    SeqListfunc.insert(list, (ListNode *)&t3, 0); //头插入法
    SeqListfunc.insert(list, (ListNode *)&t4, 0); //头插入法
    SeqListfunc.insert(list, (ListNode *)&t5, 0); //头插入法

    // 遍历
    for (i = 0; i < SeqListfunc.length(list); i++)
    {
        teacher *tmp = SeqListfunc.get(list, i);
        if (tmp == NULL)
        {
            return -1;
        }
        printf("name = %s\t age = %d\n", tmp->name, tmp->age);
    }
    // 打印当前顺序表的长度和最大容量
    printf("length = %d, capacity = %d\n", SeqListfunc.length(list),
           SeqListfunc.capacity(list));

    // 删除节点
    SeqListfunc.delete(list, 0);

    // 打印当前顺序表的长度和最大容量
    printf("length = %d, capacity = %d\n", SeqListfunc.length(list),
           SeqListfunc.capacity(list));

    while (SeqListfunc.length(list) > 0)
    {
        SeqListfunc.delete(list, 0);
    }
    // 打印当前顺序表的长度和最大容量
    printf("length = %d, capacity = %d\n", SeqListfunc.length(list),
           SeqListfunc.capacity(list));

    return 0;
}
